package redis

import (
	"bluebell/models"
	"bluebell/pkg/utils"
	"fmt"
	"strconv"
	"time"
)

// GetUserInfoInRedis 获取用户信息缓存
func GetUserInfoInRedis(id int64) (result map[string]string) {
	result, _ = rdb.HGetAll("user:info:" + strconv.Itoa(int(id))).Result()
	return
}

// SetUserInfoInRedis 设置用户信息缓存
func SetUserInfoInRedis(id int64, user *models.User) (result map[string]string) {
	fmt.Println("^^^^^^^^^^^^")
	userInfo := utils.StructToMap(user)
	fmt.Println("@@@@@@@@@@@@@")
	delete(userInfo, "password")
	rdb.HMSet("user:info:"+strconv.Itoa(int(id)), userInfo)
	rdb.Expire("user:info:"+strconv.Itoa(int(id)), time.Minute*1)
	result, _ = rdb.HGetAll("user:info:" + strconv.Itoa(int(id))).Result()
	return
}
